package edu.sandau.basic.controller;

import edu.sandau.basic.domain.MenuLang;
import edu.sandau.basic.service.MenuLangService;
import edu.sandau.basic.vo.BasicMsg;
import edu.sandau.basic.vo.MenuLangVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Tag(name = "菜单多语言管理", description = "菜单语言翻译的增删改查接口")
public class MenuLangController {

    @Autowired
    private MenuLangService menuLangService;

    @Operation(summary = "查询指定菜单的语言翻译")
    @GetMapping("/menu_langs/{menuId}")
    public List<MenuLang> getMenuLangs(@PathVariable Integer menuId) {
        return menuLangService.getMenuLangsByMenuId(menuId);
    }

    @Operation(summary = "新增菜单翻译")
    @PostMapping("/menu_langs")
    public BasicMsg addMenuLang(@RequestBody MenuLangVo vo) {
        MenuLang lang = new MenuLang();
        lang.setMenuId(vo.getMenuId());
        lang.setLanguage(vo.getLanguage());
        lang.setName(vo.getName());
        lang.setDescription(vo.getDescription());
        menuLangService.addMenuLang(lang);
        return BasicMsg.ok("菜单语言添加成功");
    }

    @Operation(summary = "更新菜单翻译")
    @PutMapping("/menu_langs/{id}")
    public BasicMsg updateMenuLang(@PathVariable Integer id, @RequestBody MenuLangVo vo) {
        MenuLang lang = new MenuLang();
        lang.setId(id);
        lang.setLanguage(vo.getLanguage());
        lang.setName(vo.getName());
        lang.setDescription(vo.getDescription());
        menuLangService.updateMenuLang(lang);
        return BasicMsg.ok("菜单语言更新成功");
    }

    @Operation(summary = "删除菜单翻译")
    @DeleteMapping("/menu_langs/{id}")
    public BasicMsg deleteMenuLang(@PathVariable Integer id) {
        menuLangService.deleteMenuLang(id);
        return BasicMsg.ok("菜单语言删除成功");
    }
}
